const ftp = require('ftp');
const fs = require('fs');
/**
 * @version 1.0.0
     * @param config 
     * {
     * host:'localhost',
     * port:'21',
     * user:'guest',
     * password:'guest12345',
     * secure:'false',
     * secureOptions:'none',
     * connTimeout:10000,
     * pasvTimeout:10000,
     * keepalive:10000}
     */
class ftpClient {
    constructor(config) {
        this.init(config);
    }
    init(config) {
        this.config = config;
    }

    connectFtp(){
        return new Promise((resolve,reject)=>{
            if (this.config == null) {
                reject(new Error('no config'));
            }
            let c = new ftp();

            c.on('ready', () => {
                console.log('ftp connect ok')
                resolve(c);
            });

            c.once('error', (err) => {  //错误事件只要一次
                reject(err);
            });
            c.connect(this.config);
        })
    }

}

module.exports=ftpClient;

